package com.oa.oaspccommon.config;


import com.oa.oaspccommon.interceptor.AuthenInterceptor;
import com.oa.oaspccommon.interceptor.OthersInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;


import java.util.ArrayList;
import java.util.List;

/**
 * @author Sdx
 * 2021-04-17
 */
@Configuration
public class JwtInterceptorConfig implements WebMvcConfigurer {
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        List<String> excludePath =new ArrayList<>();
        excludePath.add("/user_register");//注册
        excludePath.add("/login");//登录
        excludePath.add("/logout");//登出
        registry.addInterceptor(myInterceptor())
                .excludePathPatterns(excludePath)
                .addPathPatterns("/**");
        //        registry.addInterceptor(myOtherInterceptor());
    }
    //创建自定义的拦截器对象，并交给spring管理

    @Bean
    public HandlerInterceptor myInterceptor(){
        return new AuthenInterceptor();
    }
    @Bean
    public HandlerInterceptor myOtherInterceptor(){
        return new OthersInterceptor();
    }
}
